<template>
	<view class="page__content">
		<up-navbar :title="pageConfig.titleName" leftIconColor="#fff" rightIconColor="#fff" :autoBack="true"
			:fixed="false">
		</up-navbar>

		<view class="page__content__main">
			<view class="x-f" style="padding: 15px 30px;margin-top: 15px;background-color: #fff;border-radius: 20px;"
				v-for="(item,index) in DeviceInfoList" :key="index" @click="ChoiceDevice(item)">
				<u--image :showLoading="true" :src="judgeImg(item.FilePath)" mode="widthFix" width="35px"
					height="35px"></u--image>

				<view style="margin-left: 15px;flex: 1;">
					<view class="x-f" style="font-size: 14px;font-weight: 600;">
						<text>{{item.MeasureName}}</text>
						<text>_</text>
						<text>{{item.MeasureSpec}}</text>
					</view>

					<view style="margin-top: 8px;">
						<u-tag style="width: fit-content;" size="mini" :text="item.Communication"></u-tag>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script setup lang="ts">
	import { reactive, computed, onMounted, ref, nextTick, getCurrentInstance, watch } from 'vue'
	import { onLoad, onShow } from '@dcloudio/uni-app'
	import { useMainStore, useQmsStore, usePermissionStore, useUserStore, useBluetoothStore } from '@/store';
	const qmsStore = useQmsStore();
	const mainStore = useMainStore();
	const permissionStore = usePermissionStore();
	const userStore = useUserStore();
	const bluetoothStore = useBluetoothStore();
	import useRequestQueue from '@/uni_modules/mc-ui/libs/http/UniversalRequestQueue';
	const { request, requestByUrl, onAllComplete, onError } = useRequestQueue();


	let pageConfig = reactive({
		titleName: "",
		ClassifyID: null,
	});

	let DeviceInfoList = ref<any>([]);

	// 获取设备列表
	function GetDeviceInfoArr(id : any, Ids ?: any) {
		let obj = {};
		if (Ids) {
			obj = {
				UpID: id,
				EquipmentBrandID: Ids
			}
		} else {
			obj = {
				UpID: id,
			}
		};

		request({
			config: {},
			url: 'APP_JLSBLIST',
			method: 'POST',
			data: obj,
			success: async (ret : any) => {
				console.log(ret);
				if (ret.status == 200) {

					DeviceInfoList.value = ret.data.ds
				}

			}
		})
	};

	// 选中设备
	const ChoiceDevice = (data : any) => {

		qmsStore.DeviceLinkConfig.tempData_device.deviceInfo = uni.$utils.deepClone(data);

		uni.navigateTo({
			url: "/st_qms/page_device/page_device_scan"
		});
	}

	const judgeImg = (data : any) => {
		if (uni.$utils.isEmpty(data)) {
			return ""
		} else if (!/^http[s]?:\/\/.*/.test(data)) {
			mainStore.appConfigInfo.IPAgreement + mainStore.appConfigInfo.serverIP + data;
		} else {
			return data
		}
	}



	onLoad((option : any) => {
		console.log(option);
		pageConfig.titleName = option.Name;
		pageConfig.ClassifyID = option.ClassifyID;

		// 获取设备列表数据
		GetDeviceInfoArr(option.ClassifyID, '');

	})
</script>

<style lang="scss">
	* {
		padding: 0;
		margin: 0;
		box-sizing: border-box;
	}

	.page__content {
		background-color: #f9f9f9;
		height: 100vh;

		&__main {
			padding: 0 20px;

			.u-image {
				margin: 0 auto !important;
			}
		}

	}
</style>